package com.apes.fn.fico.expense.platformFee.process;

import com.apes.fn.fico.expense.platformFee.CommonFeeProcess;
import com.apes.fn.scm.vipSettle.model.VipUnionSettle;
import com.apes.fn.scm.vipSettle.model.VipUnionSettleItem;
import com.apes.fn.scm.vipSettle.repository.VipUnionSettleRepository;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.framework.util.MapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.stream.Stream;

/**
 * 会员联盟生成平台费用细项单据
 */
@Service
public class VipUnionFeeProcess extends CommonFeeProcess {

    @Autowired
    VipUnionSettleRepository vipUnionSettleRepository;

    @Override
    public void process(SimpleRequest request) {
        String id = request.get("id");
        VipUnionSettle vipUnionSettle = vipUnionSettleRepository.findOne(id);
        createExpense(MapUtil.mapper("order", vipUnionSettle));
    }

    /**
     * 平台服务费
     *
     * @param map {"order": VipUnionSettle}
     */
    @Override
    public Map<String, Object> getExpenseModel(Map map) {
        VipUnionSettle vipUnionSettle = (VipUnionSettle) map.get("order");
        return MapUtil.mapper("order", vipUnionSettle.getId(), "orderType", "VipUnionSettle",
                "source", vipUnionSettle.getRetailOrder(), "sourceBusinessType", "retailOrder",
                "summary", "", "incomeTypeId", "A09", "expenseDetailsTypeId", "002046",
                "paymentAmount", vipUnionSettle.getSettlementAmount(),"date",vipUnionSettle.getCreateDate(),
                "expenseAmount", vipUnionSettle.getPlatformManagementFee(),
                "deptId", vipUnionSettle.getDept().getId(),
                "companyId", vipUnionSettle.getCompany().getId());
    }

    @Override
    public boolean support(String type) {
        return "VipUnionSettle".equals(type);
    }

}
